package network2023;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/5/8 18:35
 */
public class UdpDictServer extends UdpEchoServer {

    private Map<String, String> dictionary;

    public UdpDictServer(int port) throws SocketException {
        super(port);
        dictionary = new HashMap<>();
        dictionary.put("cat", "小猫");
        dictionary.put("dog", "小狗");
    }

    @Override
    public String process(String request) {
        return dictionary.getOrDefault(request, "无法翻译~");
    }

    @Override
    public void start() throws IOException {
        super.start();
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer udpDictServer = new UdpDictServer(9090);
        udpDictServer.start();;
    }
}
